import { create } from 'zustand'

export type Command = {
    tool: string,
    action: string,
    target?: string,
    property?: string,
    value?: string
}

type CommanderState = {
    commands: Command[]
    addCommands: (cmds: Command[]) => void

    checkCommand: () => Command | {}
    confirmCommand: (command: Command) => void
}

export const useCommander = create<CommanderState>((set, get) => ({
    commands: [],
    addCommands: (cmds: Command[]) => set(state => ({ commands: [...state.commands, ...cmds] })),

    checkCommand: () => get().commands.length > 0 ? get().commands[0] : {},
    confirmCommand: (command: Command) => set(state => ({ commands: state.commands.filter(item => item != command) }))
}))